var core = require('../../utils/core.js')

Page({
  data: {
    focus: false,
    inputValue: '',

    index: 0,

    array: [ '欺诈', '色情', '不实信息', '骚扰', '其他' ],

    imgs: [],
    qcode:'',

    
    fee:'',
    

    
    label_id:0,
    label_name:'',
    lat:'',
    lng:'',
    address:'',
    addr_name:'',

    title:'',
    desc:'',
    tel:'',
    wx:'',
  },
  bindPickerChange: function(e) {
    //console.log('picker发送选择改变，携带值为', e.detail.value)
    // var that=this
    // this.setData({
    //   index: e.detail.value,
    //   top_id:that.data.top_array[e.detail.value].id,
    //   fee:that.data.typeid=='1'? that.data.top_array[e.detail.value].credit2:that.data.top_array[e.detail.value].credit1,
    // })
  },
  onShow:function(){
    var label=wx.getStorageSync('label')
    if(label){
      label=JSON.parse(label);
      this.setData({label_id:label.id,label_name:label.name})
    }
  },
  onLoad:function(){
   
  },
  
  
  label:function(){
    wx.navigateTo({
      url:"/pages/release/label"
    })
  },
  address:function(){
    var self=this
     wx.getLocation({
        type: 'gcj02',
        success(res) {
            
          wx.authorize({
            scope: 'scope.userLocation',
            success() {
              wx.chooseLocation({
                success(res) {  
                 // console.log(res)
                 self.setData({
                    lat: res.latitude,lng:res.longitude,addr_name:res.name,address:res.address
                  })
                },
                fail() {
                  //console.log('地址选择取消')
                }
              })
            },
            fail() {
              //console.log('拒绝授权')  
            }
          })
        }
    });
  },


   // 上传图片
   chooseImg: function (e) {
    var that = this;
    var imgs=this.data.imgs
    core.upload(function(res){
      // console.log(res)
      if(res.error==0){
        imgs.push(res.url);
        that.setData({imgs:imgs})
      }
    });
  },
  // 删除图片
  deleteImg: function (e) {
    var imgs = this.data.imgs;
    var index = e.currentTarget.dataset.id;
   var that=this
    wx.showModal({
      title: '提示',
      content: '确定要删除吗？',
      success: function (sm) {
        if (sm.confirm) {
            // 用户点击了确定 可以调用删除方法了
            imgs.splice(index, 1);
            that.setData({
              imgs: imgs
            });
          } else if (sm.cancel) {
            //console.log('用户点击取消')
          }
        }
    })
  },
  


   // 上传二维码图片
   chooseqcode: function (e) {
    var that = this;
    core.upload(function(res){
      // console.log(res)
      if(res.error==0){
        that.setData({qcode:res.url})
      }
    });
  },
  // 删除二维码
  deleteqcode: function (e) {
   
   var that=this
    wx.showModal({
      title: '提示',
      content: '确定要删除吗？',
      success: function (sm) {
        if (sm.confirm) {
            // 用户点击了确定 可以调用删除方法了
            that.setData({
              qcode: ''
            });
          } else if (sm.cancel) {
            //console.log('用户点击取消')
          }
        }
    })
  },
  
  getval(e) {
    var name=e.target.id
    this.setData({
      [name]: e.detail.value
    })
  },
  submit:function(){

    wx.showToast({
      'title':'提交成功',
      'icon':'success'
    })
    return
    var self=this
    var data={
      title:self.data.title,
      label_id:self.data.label_id,
      desc:self.data.desc,
      imgs:JSON.stringify(self.data.imgs),
      lat:self.data.lat,
      lng:self.data.lng,
      address:self.data.address,
      tel:self.data.tel,
      wx:self.data.wx,
      qcode:self.data.qcode,
      fee:self.data.fee,
    }
    // console.log(data)
    // return
    core.post("Addneed",data,function(res){
      // console.log(res)
      if(res.code==1){
        wx.showToast({
          'title':res.msg,
          'icon':'success',
          success:function(){
            setTimeout(function(){
              wx.switchTab({
                url:"/pages/index/index"
              })
            },1000)           
          }
        })
       
      }else{
        wx.showToast({
          'title':res.msg,
          'icon':'none'
        })
      }
    })
  }
  
})
